import {
  upInfoByMidRequest,
  upFlowByMidRequest,
} from "../../../../server/index";

Component({
  data: {
    loading: true,
    info: {},
    id: "", // mid参数
    model: {
      weight: "胡椒指数",
      fans: "粉丝总数",
      videos: "视频总数",
      coins: "充电总人数",
    },
  },
  properties: {
    mid: {
      type: String,
      value: "",
      observer(mid) {
        this.setData({ id: mid });
        this.getUpInfo(mid);
      },
    },
  },
  methods: {
    // 根据mid获取Up主信息
    getUpInfo(mid: string) {
      upInfoByMidRequest({ mid }).then((res: any) => {
        this.setData({
          loading: false,
          info: res,
        });
      });
    },
    // 添加关注
    flowHandler() {
      upFlowByMidRequest({ mid: this.data.id }).then(() => {
        wx.showToast({
          icon: "success",
          title: "添加关注成功",
        });
        this.setData({
          info: {
            ...this.data.info,
            isCollected: true,
          },
        });
      });
    },
  },
});
